package com.ybwh.springboot2.common.mybatis.plus;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * <p>
 * 获取当前用户塞到ThreadLocal
 * </p>
 *
 * @author fanbeibei
 * @version V1.0
 * @since 2019/4/25 17:45
 */
@Slf4j
@Aspect
@Component
public class UpdateFieldAop {
    @Around(value = "execution(public * com.ybwh.*.*.controller..*.*(..)))")
    public Object execute(ProceedingJoinPoint joinPoint) throws Throwable {

        Long userId = getUserId(joinPoint);
        DaoContext.setUpdateId(userId);
        DaoContext.setUpdateTime(LocalDateTime.now());
        return joinPoint.proceed();
    }

    private Long getUserId(ProceedingJoinPoint joinPoint) {
        // TODO 获取用户ID逻辑
        return 1234567L;
    }


}
